$(function () {
    $("#jqGrid").Grid({
        url: '../modulemaintainplan/list2',
        colModel: [
            {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
            {label: '维护规程名称', name: 'mainteBaseId', index: 'MAINTE_BASE_ID', hidden: true},
            {label: '计划名称', name: 'planName', index: 'PLAN_NAME', width: 120,},
            {label: '模具号', name: 'moduleNo', index: 'MODULE_NO', width: 120},
            // {label: '模具名称', name: 'moduleName', index: 'moduleName', width: 120},
            {
                label: '开始时间', name: 'planStartDate', index: 'PLAN_START_DATE', width: 80,
                formatter: function (value) {
                    return transDate(value, "yyyy-MM-dd");
                }
            },
            {
                label: '结束时间', name: 'planEndDate', index: 'PLAN_END_DATE', width: 80,
                formatter: function (value) {
                    return transDate(value, "yyyy-MM-dd");
                }
            },
            {label: '执行人', name: 'repairUsername', index: 'REPAIR_USERNAME', width: 120},
            {
                label: '执行时间', name: 'actionDate', index: 'ACTION_DATE', width: 80,
                formatter: function (value) {
                    return transDate(value, "yyyy-MM-dd");
                }
            },
            {
                label: '维护进度', index: 'PROGRESS', width: 80,
                formatter: function (value, col, row) {
                    return sysEnums.MOLD_MAINTENANCE_PLAN_PROGRESS[row.progress];
                }
            },
            {name: 'progress', hidden: true},
            {label: '', name: 'isDelay', index: 'IS_DELAY', hidden: true,},
            {
                label: '是否延期', name: '', index: '', width: 80,
                formatter: function (value, col, row) {
                    var isDelay = row.isDelay;
                    if (isDelay != null && isDelay != "null") {
                        return sysEnums.IS_DELAY[isDelay];
                    } else {
                        return "暂无";
                    }
                }
            },
            {
                label: '是否超时', name: 'isPutOff', index: 'IS_PUT_OFF', width: 80, algin: 'center',
                formatter: function (value) {
                    // return sysEnums.IS_PUT_OFF[value]; 根据维护时间判断
                    return value === 0 ?
                        '<span class="label label-success">否</span>' :
                        '<span class="label label-danger">是</span>';
                }
            }, {
                label: '是否异常', name: 'error', index: 'error', width: 80, algin: 'center',
                formatter: function (value) {
                    // return sysEnums.IS_PUT_OFF[value]; 根据维护时间判断
                    return value === 0 ?
                        '<span class="label label-success">否</span>' :
                        '<span class="label label-danger">是</span>';
                }
            },
            {
                label: '记录单填写', name: '', index: '', width: 60,
                formatter: function (value, col, row) {
                    var status = row.reviewStatus;
                    if (status == 2) {
                        return "<button class='btn btn-outline btn-info' onclick='vm.addRecord(\"" + row.id + "\")'><i class='fa fa-file-text-o'></i></button>";
                    } else {
                        return "填写完成";
                    }
                }
            },
            {name: 'replacePartProgress', hidden: true},
            {
                label: '换件进度', index: 'REPLACE_PART_PROGRESS', width: 80,
                formatter: function (value, col, row) {
                    return sysEnums.MOLD_REPAIR_PROGRESS[row.replacePartProgress];
                }
            },
            {
                label: '换件记录', width: 80, sortable: false,
                formatter: function (value, col, row) {
                    return "<button title='' class='btn btn-outline btn-info' onclick='vm.addReplacePartRecord(\"" + row.planName + "\", \"" + row.moldId + "\")'><i class='fa fa-file-text-o'></i></button>";
                }
            },
            {
                label: '审核详情', name: 'devCode', index: 'DEV_CODE', width: 80, sortable: false,
                formatter: function (value, col, row) {
                    return "<button class='btn btn-outline btn-info' id='recordsText' onclick='vm.shviewOption(\"" + escape(JSON.stringify(row)) + "\")'>&nbsp;详情</button>";
                }
            },
            {
                label: '维护项', name: '', index: '', width: 80,
                formatter: function (value, col, row) {
                    return "<button class='btn btn-outline btn-info' onclick='vm.goOption(\"" + row.id + "\")'><i class='fa fa-file-text-o'></i></button>";
                }
            },
            {
                label: '维护记录', name: '', index: '', width: 80,
                formatter: function (value, col, row) {
                    return "<button class='btn btn-outline btn-info' onclick='vm.showRecord(\"" + row.id + "\")'><i class='fa fa-file-text-o'></i></button>";
                }
            }

        ]
    });
    vm.getTypeTree();
});


var typeTree;
var setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "superType",
            rootPId: 0
        },
        key: {
            url: "nourl",
            name: "typeName" //name 与 typeName 绑定
        },
    },
    callback: {
        onClick: function () {
            var node = typeTree.getSelectedNodes();
            var level = node[0].level;
            if (level > 0) {
                vm.q.moduleTypeName = node[0].id;
                vm.query();
            }
        }

    }
};


var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        repairUserList: [],
        moduleMaintainPlan: {
            planEndDate: '',
            planStartDate: '',
            remark: '',
            planName: '',
            moduleCode: '',
            id: '',
            repairUser: '',
            planEndDates: '',
            replacePartProgress: 0,
            isPut: ''
        },
        maintaPlanChangeRecords: {
            changeReason: '',
            remark: '',
            modelMaintaPlanId: ''
        },
        moduleError: {
            dealOpinion: '',
            isOff: 1,
            moduleCode: '',
            id: '',
        },
        ruleValidate: {
            name: [
                {required: true, message: '名称不能为空', trigger: 'blur'}
            ]
        },
        q: {
            name: '',
            moduleNo: '',
            moduleTypeName: '',
            beginTime: '',
            endTime: '',
        },
        // 审核参数VO
        approveParam: {
            approveIdList: [],
            status: 1,
            remark: ''
        },
        isDisabled: false,
        remark2: "",//用于延期结束计划提交时数据
        dispatchParam: {
            id: '', // 维修工单ID
            repairUser: [] // 派工用户
        },
        mainPersonnel: []//维护人员列表
    },
    methods: {
        //点击选择框，进行删除
        pointPopup(Item, index) {
            this.mainPersonnel.splice(index, 1);
            for (let i = 0; i < this.dispatchParam.repairUser.length; i++) {
                if (Item.userId == this.dispatchParam.repairUser[i]) {
                    this.dispatchParam.repairUser.splice(i, 1)
                }
            }
        },
        /**
         * 1.检查这个id在数组中有没有，有删除，没有加入
         *
         * @param id
         */
        pointPersonnel(Item) {
            if (this.dispatchParam.repairUser.length > 5) {
                alert('只可以指定7位维修人员！');
                return
            }
            if (Item.userId) {
                if (this.dispatchParam.repairUser.length > 0) {
                    //添加
                    if (this.dispatchParam.repairUser.indexOf(Item.userId) == -1) {
                        this.dispatchParam.repairUser.push(Item.userId)
                    } else {
                        //删除
                        for (let i = 0; i < this.dispatchParam.repairUser.length; i++) {
                            if (Item.userId == this.dispatchParam.repairUser[i]) {
                                this.dispatchParam.repairUser = this.dispatchParam.repairUser.filter(item => !item.toString().includes(Item.userId))
                            }
                        }
                    }
                } else {
                    this.dispatchParam.repairUser.push(Item.userId)
                }
                //进行第二步 在push 人名数组
                this.mainPersonnel = []
                for (let i = 0; i < this.dispatchParam.repairUser.length; i++) {
                    for (let j = 0; j < this.repairUserList.length; j++) {
                        if (this.dispatchParam.repairUser[i] == this.repairUserList[j].userId) {
                            this.mainPersonnel.push({
                                name: this.repairUserList[j].userName + '(' + this.repairUserList[j].nickName + ')',
                                userId: this.repairUserList[j].userId
                            })
                        }
                    }
                }
            }
        },
        commit: function () {
            // 编制完毕后提交审核
            var planId = getSelectedRow("#jqGrid");
            if (!planId) {
                return;
            }
            var data = getSelectedRowData("#jqGrid");
            if (data.replacePartProgress !== '0' && data.replacePartProgress !== '2') {
                alert('当前需求计划审核中或已通过，无需重复提交!');
                return;
            }
            Ajax.request({
                url: '../modulemaintainplan/commitApproveReplacePart',
                params: {'id': data.id},
                type: 'POST',
                successCallback: function (res) {
                    alert('提交成功!');
                    setTimeout(function () {
                        location.reload();
                    }, 1000);
                }
            });
        },
        deptCheck: function () {
            // 必须选中记录
            var data = getSelectedRowData("#jqGrid");
            if (!data) {
                return;
            }
            if (data.replacePartProgress !== '1') {
                alert("只可以审核处于车间审核状态的规程信息", function () {
                    vm.reload();
                })
                return;
            }
            // 构建审批参数
            vm.approveParam = {
                approveIdList: [data.id],
                status: '1',
                remark: ''
            }
            openWindow({
                title: "审核信息",
                area: ['450px', '300px'],
                content: jQuery("#reviewLayer"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    if (typeof (vm.approveParam.status) == 'undefined') {
                        alert("请选择审核状态");
                        return;
                    }
                    Ajax.request({
                        url: '../modulemaintainplan/deptCheckReplacePart',
                        params: JSON.stringify(vm.approveParam),
                        contentType: "application/json",
                        type: 'POST',
                        successCallback: function (res) {
                            alert('审核成功!', function () {
                                layer.closeAll();
                                vm.reload();
                            });
                        }
                    });
                }
            });
        },
        //审核详情
        shviewOption: function (res) {
            var data = JSON.parse(unescape(res))
            Ajax.request({
                url: '../sysProcess/approve',
                params: {bussinessId: data.id},
                type: 'POST',
                successCallback: function (res) {
                    var approveProcessList = res.approveProcessList;
                    if (approveProcessList.length == 0) {
                        iview.Message.error("暂无审批记录");
                        return;
                    }
                    var dom = "<div class='details'><table>";
                    for (var i = 0; i < approveProcessList.length; i++) {
                        var approveProcess = approveProcessList[i];
                        dom += '<tr><td>' + approveProcess.approveDate + '</td>';
                        dom += '<td align="left">' + approveProcess.roleName + '-' + approveProcess.name + '： ' + sysEnums.CHECK_FLAG[approveProcess.status];
                        if (approveProcess.remark) {
                            dom += '<br />备注：' + approveProcess.remark;
                        }
                        dom += '</td></tr>'
                    }
                    dom += '</table></div>'
                    layer.open({
                        type: 1,
                        title: "审核详情",
                        closeBtn: 0,
                        area: ['500px'],
                        offset: '10vh',
                        shadeClose: true,
                        skin: 'yourclass',
                        content: dom
                    });
                }
            });
        },
        addReplacePartRecord: function (repairCode, moldId) {
            openWindow({
                type: 2,
                area:['100%','100%'],
                title: '<i class="fa fa-bars"></i> 换件记录',
                content: '../module/modulereplacepartForSelect.html?replaceCode=' + repairCode + '&typeMethod=2' + '&moldId=' + moldId
            })
        },
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.moduleMaintainPlan = {
                replacePartProgress: 0,
                planEndDate: '',
                planStartDate: '',
                remark: '',
                planName: '',
                isPutOff: 0,
                isSure: 0,
                isOut: 0,
                id: '',
                repairUser: '',
                moduleCode: '',
            };
        },
        update: function (event) {
            let id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id);
        },
        saveOrUpdate: function (event) {
            var url = vm.moduleMaintainPlan.id == (null || '') ? "../modulemaintainplan/save" : "../modulemaintainplan/update";
            Ajax.request({
                url: url,
                params: JSON.stringify(vm.moduleMaintainPlan),
                type: "POST",
                contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                        vm.reload();
                    });
                }
            });
        },
        del: function (event) {
            var ids = getSelectedRows("#jqGrid");
            if (ids == null) {
                return;
            }
            confirm('确定要删除选中的记录？', function () {
                Ajax.request({
                    url: "../modulemaintainplan/delete",
                    params: JSON.stringify(ids),
                    type: "POST",
                    contentType: "application/json",
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            });
        },
        getInfo: function (id) {
            Ajax.request({
                url: "../modulemaintainplan/info/" + id,
                async: true,
                successCallback: function (r) {
                    vm.moduleMaintainPlan = r.moduleMaintainPlan;
                }
            });
        },
        reload: function (event) {
            vm.showList = true;
            var beginTime = vm.q.beginTime;
            if (beginTime != "" && beginTime != "null") {
                var date = new Date(beginTime);
                // beginTime = date.format("yyyy-MM-dd");
                beginTime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
            }
            var endTime = vm.q.endTime;
            if (endTime != "" && endTime != "null") {
                var date = new Date(endTime);
                endTime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
            }
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    'name': vm.q.name,
                    'moduleNo': vm.q.moduleNo,
                    'moduleType': vm.q.moduleTypeName,
                    'beginTime': beginTime,
                    'endTime': endTime,
                },
                page: page
            }).trigger("reloadGrid");
        },
        reloadSearch: function () {
            vm.q = {
                name: '',
                moduleNo: '',
                moduleTypeName: '',
                beginTime: '',
                endTime: '',
            };
            typeTree.cancelSelectedNode();
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        getModuleBase: function () {
            openWindow({
                type: 2,
                title: '<i class="fa fa-file-text-o"></i> 模具清单',
                content: '../module/moduleArchiveSelect.html',
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var iframeWin = window["layui-layer-iframe" + index];
                    var res = iframeWin.getModuleArchives();
                    console.log(res);
                    if (!res) {
                        iview.Message.error("请选择一条记录");
                    } else {
                        var date = new Date();
                        var month = zeroFill(date.getMonth() + 1);//月
                        var day = zeroFill(date.getDate());//日
                        var days = date.getFullYear() + "" + month + "" + day;
                        vm.moduleMaintainPlan.moduleCode = res.moduleCode;
                        //车间
                        //vm.moduleMaintainPlan.workshop = res.subShopName;
                        vm.moduleMaintainPlan.planName = res.moduleCode + "_" + days;
                        layer.close(index);
                    }
                }
            })
        },
        //添加指派人
        assignment: function () {
            vm.mainPersonnel = [];
            let id = getSelectedRow('#jqGrid');
            if (!id) {
                return;
            }
            let data = getSelectedRowData("#jqGrid");
            let progress = data.progress;
            if (progress != '1') {
                layer.alert('只可以派工[待派工]状态的工单！', {icon: 5});
                return;
            }
            //判断是否存在指派人
            this.dispatchParam = {
                id: id,
                repairUser: []
            };
            vm.getAssign();
            openWindow({
                title: "指派",
                area: ['800px', '450px'],
                content: jQuery("#assignment"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    // 转换下类型
                    vm.dispatchParam.repairUser = vm.dispatchParam.repairUser.join(",")
                    Ajax.request({
                        url: "../modulemaintainplan/addRepUser",
                        params: JSON.stringify(vm.dispatchParam),
                        type: "POST",
                        contentType: "application/json",
                        successCallback: function (r) {
                            alert('操作成功', function (index) {
                                vm.reload();
                            });
                        }
                    });
                    layer.close(index);
                }
            });
        },
        getAssign: function () {
            //获取当前登录部门的维修组人员信息
            Ajax.request({
                url: '../modulemaintainplan/repairUser',
                async: false,
                successCallback: function (r) {
                    vm.repairUserList = r.list;
                    // var users = r.repairUserList;
                    // for (let user of users) {
                    //     vm.planPerson.push(user);
                    // }
                }
            })
        },
        start: function () {
            let id = getSelectedRow('#jqGrid');
            if (!id) {
                return;
            }
            let data = getSelectedRowData("#jqGrid");
            if (data.progress != '2') {
                layer.alert('只可以开始执行[待维修]状态的工单！', {icon: 5});
                return;
            }
            vm.moduleMaintainPlan.id = data.id;
            vm.moduleMaintainPlan.moduleCode = data.moduleCode;
            Ajax.request({
                url: '../modulemaintainplan/start',
                params: JSON.stringify(vm.moduleMaintainPlan),
                type: "POST",
                contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功,请填写记录单！', function (index) {
                        layer.closeAll();
                        vm.reload();
                    });
                }
            })
        },
        //查看维护记录
        showRecord: function (id) {
            openWindow({
                type: 2,
                title: '<i class="fa fa-file-text-o"></i> 记录查看',
                area:['100%','100%'],
                content: '../module/modulePlanRecord.html?planId=' + id
            })
        },
        isOutTime: function () {
            var id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            var data = getSelectedRowData("#jqGrid");
            // 已结束工单不能申请延期
            if (data.progress == '5' || data.progress == '6') {
                iview.Message.error("已结束或关闭工单不能申请延期");
                return;
            }
            var isDelay = data.isDelay;
            if (isDelay == 1) {
                alert("当前任务未审核!");
            } else {
                Ajax.request({
                    url: "../modulemaintainplan/isOutTime",
                    type: 'POST',
                    params: {"id": data.id},
                    async: false,
                    successCallback: function (r) {
                        if (r.res > 0) {//大于0时,
                            vm.updateOutTime();
                        } else {
                            confirm("当前任务未超计划时间,确认申请延期?", function () {
                                layer.closeAll();
                                vm.updateOutTime();
                            })
                        }
                    }
                });
            }
        },
        updateOutTime: function () {
            var id = getSelectedRow("#jqGrid");
            //获取计划结束日期
            if (id == null) {
                return;
            }
            openWindow({
                type: 2,
                title: '<i class="fa fa-file-text-o"></i> 延期申请',
                area: ['70%', '70%'],
                content: '../module/addModuleApply.html',
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var iframeWin = window["layui-layer-iframe" + index];
                    var res = iframeWin.getFormDates();
                    res.ticketId = id;
                    Ajax.request({
                        url: "../maintaplanchangerecords/save",
                        params: JSON.stringify(res),
                        type: "POST",
                        contentType: "application/json",
                        successCallback: function (r) {
                            alert('操作成功', function (index) {
                                layer.closeAll();
                                vm.reload();
                            });
                        }
                    });
                }
            });
        },
        //结束计划
        end: function () {
            var ids = getSelectedRows("#jqGrid");
            if (ids == null) {
                return;
            }
            var data = getSelectedRowData("#jqGrid");
            vm.moduleMaintainPlan.id = data.id;
            var progress = data.progress;
            if (progress == '5' || progress == '6') {
                iview.Message.error("工单已完成或关闭，请确认！");
                return;
            }
            vm.moduleMaintainPlan.moduleCode = data.moduleCode;
            openWindow({
                title: "结束计划",
                area: ['450px', '250px'],
                content: jQuery("#remark_div"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    vm.moduleMaintainPlan.remark = vm.remark2;
                    Ajax.request({
                        url: '../modulemaintainplan/endProcessPlan',
                        params: JSON.stringify(vm.moduleMaintainPlan),
                        type: "POST",
                        contentType: "application/json",
                        successCallback: function (r) {
                            alert('当前计划已结束，所有相关执行模块已经停止！', function (index) {
                                vm.reload();
                                layer.closeAll();

                            });
                        }
                    });

                    layer.close(index);

                    // console.log(vm.remark2);
                }
            });
        },
        //异常上报
        error: function () {
            var id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            var data = getSelectedRowData("#jqGrid");
            // 已结束工单不能上报异常
            if (data.progress == '5' || data.progress == '6') {
                iview.Message.error("已结束或关闭的工单不能上报异常");
                return;
            }
            var e = hasError(id);
            if (e > 0) {
                alert("当前记录已经添加异常");
            } else {
                openWindow({
                    type: 2,
                    title: '<i class="fa fa-file-text-o"></i> 添加异常',
                    area: ['70%', '70%'],
                    content: '../module/addErrorPlan.html',
                    btn: ['确定', '取消'],
                    btn1: function (index) {
                        var iframeWin = window["layui-layer-iframe" + index];
                        var res = iframeWin.getFormDates();
                        var params = {
                            'id': id, 'dealOpinion': res.dealOpinion,
                            'dealSuggest': res.dealSuggest, 'delFlag': res.delFlag,
                            'errorDisStatus': res.errorDisStatus, 'isOff': res.isOff,
                            'isReplaceSparepart': res.isReplaceSparepart
                        }
                        Ajax.request({
                            url: "../modulemaintainplan/addError",
                            params: JSON.stringify(params),
                            type: "POST",
                            contentType: "application/json",
                            successCallback: function (r) {
                                alert('操作成功', function (index) {
                                    layer.closeAll();
                                    vm.reload();
                                });
                            }
                        })
                    }
                });
            }
        },
        //异常处理
        dealError: function () {
            var rows = getSelectedRowDatas("#jqGrid");
            //console.log(rows)
            var ids = rows[0].id;
            console.log(ids)
            // console.log(rows[0].id)
            if (ids == null) {
                return;
            }

            var e = hasError(ids);
            //  console.log(e)
            if (e > 0) {
                var maintainRecord = ids
                Ajax.request({
                    url: "../moduleerror/getInfoByMaintainRecord/" + maintainRecord,
                    async: true,
                    successCallback: function (r) {
                        // console.log(r)
                        vm.moduleError = r.moduleError;
                        // vm.moduleError.isOff = 1
                        vm.moduleError.delFlag = 0
                        console.log(vm.moduleError)
                    }
                });
                //

                openWindow({
                    title: "异常处理",
                    area: ['400px', '250px'],
                    content: jQuery("#dealError"),
                    btn: ['确定', '取消'],
                    btn1: function (index) {
                        Ajax.request({
                            url: "../moduleerror/updateOption/",
                            params: JSON.stringify(vm.moduleError),
                            type: "POST",
                            contentType: "application/json",
                            successCallback: function (r) {
                                alert('操作成功', function (index) {
                                    vm.reload();
                                });
                            }
                        })
                        layer.close(index);
                    }
                });
            } else {
                alert("当前无异常,无需处理!");
            }
        },

        goOption: function (id) {
            // var id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            openWindow({
                type: 2,
                area:['100%','100%'],
                title: '<i class="fa fa-bars"></i> 维护规程选项',//读取维护规程选项关联表数据
                content: '../module/modulemaintainrelate.html?planID=' + id
            });
        },
        addRecord: function (id) {
            if (id == null) {
                return;
            }

            var html = '../module/modulePlanRecordWork.html?planID=' + id;
            openWindow({
                type: 2,
                title: '<i class="fa fa-file-text-o"></i> 记录单填写',
                content: html,
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var iframeWin = window["layui-layer-iframe" + index];
                    var recordList = iframeWin.getRecordList();
                    if (!recordList) {
                        iview.Message.error("页面出错！");
                    } else {
                        Ajax.request({
                            url: '../modulemaintainrecord/updateRecord',
                            async: false,
                            params: JSON.stringify(recordList),
                            type: "POST",
                            contentType: "application/json",
                            successCallback: function (r) {
                                var result = r.result;
                                if (result == 0) {
                                    alert("数据填写成功！");
                                }
                            }

                        });
                        layer.close(index);
                        vm.reload();
                    }
                }
            })

        },
        //效果确认
        isSure: function () {
            var ids = getSelectedRows("#jqGrid");
            if (ids == null) {
                return;
            }
            var data = getSelectedRowData("#jqGrid");
            vm.moduleMaintainPlan.id = ids[0];
            vm.moduleMaintainPlan.isSure = 1;
            if (data.progress != '4') {
                iview.Message.error("只有处于维修完成状态的工单才可以执行效果确认！");
                return;
                if (date.isSure != '未确定') {
                    alert("当前任务已确认完成")
                } else {
                    Ajax.request({
                        url: '../modulemaintainplan/isSure',
                        params: JSON.stringify(vm.moduleMaintainPlan),
                        type: "POST",
                        contentType: "application/json",
                        successCallback: function (r) {
                            alert('操作成功', function (index) {
                                layer.closeAll();
                                vm.reload();
                            });
                        }
                    })
                }
            }
        },
        //加载模具类型树
        getTypeTree: function () {
            Ajax.request({
                url: "../moduletype/select",
                async: true,
                successCallback: function (r) {
                    var tree = r.typeList;
                    typeTree = $.fn.zTree.init($("#typeTree"), setting, tree);
                    typeTree.expandAll(true);
                }
            });
        },
    }
});

function isHasRecord(id) {
    var i;
    Ajax.request({
        url: '../regularmaintenancerecords/isHasRecord',
        type: 'POST',
        params: {"id": id},
        async: false,
        successCallback: function (r) {
            i = r.has;
        }
    });
    return i;
}

function hasError(id) {
    var e;
    Ajax.request({
        url: '../modulemaintainplan/hasError',
        type: 'POST',
        params: {"id": id},
        async: false,
        successCallback: function (r) {
            e = r.hasError;
        }
    });
    return e;
}
